package com.myjunit.reflect;

import java.lang.reflect.Field;
import java.util.Date;

public class ReflectUtil {

	@SuppressWarnings("rawtypes")
	public static void printSetFields(Object object) {

		Field[] fields = object.getClass().getDeclaredFields();
		String objectName = object.getClass().getSimpleName();
		objectName = objectName.substring(0, 1).toLowerCase() + objectName.substring(1);

		System.out.println("��������:" + fields.length);
		for (Field field : fields) {
			String fieldName = field.getName();
			fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
			StringBuffer sb = new StringBuffer(objectName + ".set");
			sb.append(fieldName + "(");

			Class type = field.getType();
			if (type.equals(String.class)) {
				sb.append("\"1\"");
			} else if (type.equals(long.class)) {
				sb.append("1");
			} else if (type.equals(Date.class)) {
				sb.append("new Date()");
			} else if (type.equals(Long.class)) {
				sb.append("1L");
			} else if (type.equals(Integer.class)) {
				sb.append("1");
			}

			sb.append(");");
			System.out.println(sb.toString());
		}
	}
}
